﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI;
using 纸片人.Shaders;
using 纸片人.win2dEffectControl.DataClass.PixelShaderEffectDataClass;

namespace 纸片人.win2dEffectControl.DataClass.PixelShaderEffectDataClass
{
    public class DissolveEffectData : PixelShderEffectTwoData
    {
        private float threshold;

        private Color endColor = Colors.Red;
        private Color startColor = Colors.Orange;
        #region  属性
        /// <summary>
        /// 临界点 0-1
        /// </summary>
        public float Threshold { get => threshold; set { threshold = value; OnPropertyChanged(); SetIsChanges(); } }

        public Color EndColor { get => endColor; set { endColor = value; OnPropertyChanged(); SetIsChanges(); } }
        public Color StartColor { get => startColor; set { startColor = value; OnPropertyChanged(); SetIsChanges(); } }

        public override ShaderType shaderShaderPath { get; } = ShaderType.Dissolve;

        #endregion



        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {
            var source = GetSourceEffect(device, compression);
            if (source == null)
            {
                return null;
            }

            var twoSource = GetSourceTwoEffect(device, compression);

            if (shaderCodeBytes == null || twoSource == null)
                return null;
            PixelShaderEffect effect = new PixelShaderEffect(shaderCodeBytes)
            {
                Source1 = source,
                Source2 = twoSource,
                Properties =
                {
                    ["threshold"] = Threshold,
                    ["startColor"] = new Vector4(StartColor.R, StartColor.G, StartColor.B, StartColor.A),
                    ["endColor"] = new Vector4(EndColor.R, EndColor.G, EndColor.B, EndColor.A)
                }
            };
            return effect;
        }
    }
}